$file1 = "probe_HG-U133_Plus_2.cdf";
open(BUFF1,$file1);
$file2 = "hgu133plu2_probeset_geneid.txt";
open(BUFF2,$file2);
open(WRBUFF,">newcustomcdf_plus2.txt");
while($line = <BUFF2>)
{
	chomp $line;
	$line =~ s/\n//g;
	$line =~ s/\r//g;
	@array = split("\t",$line);
	#print $array[0]."\t".$hash{$array[0]}."\t".$hash2{$array[1]}."\n";
	$hash{$array[0]} = $array[1];
	$hash2{$array[1]} = "k";
	#print $array[0]."\t".$hash{$array[0]}."\t".$hash2{$array[1]}."\n";
}
while($line = <BUFF1>)
{
        #chomp $line;
        $line =~ s/\n//g;
        $line =~ s/\r//g;
        @array = split("\t",$line);
#	print $hash{$array[4]}."\n";
	if($hash{$array[4]} != "")
	{
        	if($hash1{$hash{$array[4]}} eq "k")
		{
			${"ar".$hash{$array[4]}}[${"num".$hash{$array[4]}}] = $line;
			${"num".$hash{$array[4]}}++;	
		}
		else
		{
			$hash1{$hash{$array[4]}} = "k";
			${"num".$hash{$array[4]}} = 0;
			${"ar".$hash{$array[4]}}[${"num".$hash{$array[4]}}] = $line;
			${"num".$hash{$array[4]}}++;
	}	}
}
#print @ar100289109;
$numnew = 1;
while ( my ($key, $value) = each(%hash2) ) 
{
	$aa = @{"ar".$key}%11;
	#print $key."\t".$aa."\n";;	
	$n = 1;
	$n1 = 1;
	#$numnew = 1;
	$nu = ${"num".$key};
	$nu1 = ${"num".$key}/2;
	
	$numnew1 = $key;
                                print WRBUFF "\n";
                                print WRBUFF "\n";
                                print WRBUFF "[Unit".$numnew."]"."\n";
                                print WRBUFF "Name=NONE"."\n";
                                print WRBUFF "Direction=2"."\n";
                                print WRBUFF "NumAtoms=$nu1"."\n";
                                print WRBUFF "NumCells=$nu"."\n";
                                print WRBUFF "UnitNumber=".$numnew."\n";
                                print WRBUFF "UnitType=3"."\n";
                                print WRBUFF "NumberBlocks=1"."\n";
                                print WRBUFF "\n";
                                print WRBUFF "[Unit".$numnew."_Block1]"."\n";
                                print WRBUFF "Name="."$numnew1"."\n";
                                print WRBUFF "BlockNumber=1"."\n";
                                print WRBUFF "NumAtoms=$nu1"."\n";
                                print WRBUFF "NumCells=$nu"."\n";
                                print WRBUFF "StartPosition=1"."\n";
                                print WRBUFF "StopPosition=$nu1"."\n";
                                print WRBUFF "CellHeader=X\tY\tPROBE\tFEAT\tQUAL\tEXPOS\tPOS\tCBASE\tPBASE\tTBASE\tATOM\tINDEX\tCODONIND\tCODON\tREGIONTYPE\tREGION\n";
	for($i=0;$i<@{"ar".$key};$i++)
	{
		$line = @{"ar".$key}[$i];
		@line = split("\t",$line);
		$line[4] = $numnew1;
                        $line[5] = $n;
                        $line[10] = $n;
#                       print "success\n";
                        $line = join("\t",@line);
                        print WRBUFF $line."\n";
                        if($n1%2 == 0)
                        {
                                $n++;
                        }
                        $n1++;
                        

        }
	$numnew++;
}
